package javatest3.ForWhileTest.test3;

import java.util.Random;
import java.util.Scanner;

public class method1 {
    public static void main(String[] args) {
        Random random = new Random();
        int truenum = random.nextInt(10)+1;
        int flag=0;
        System.out.println("开始猜数");
       while (true){
           Scanner scanner = new Scanner(System.in);

           int guessnum = scanner.nextInt();
           if (guessnum<truenum){
               System.out.println("猜小了");
               flag++;
           }
           if (guessnum>truenum){
               System.out.println("猜大了");
               flag++;
           }
           if (guessnum==truenum){
               System.out.println("猜对了");
               break;
           }
           if (flag<3){
               System.out.println("你还剩"+(3-flag)+"次");
           }else {
               System.out.println("你的机会用完了");
           }
       }
    }
}
